<?php
class Friend extends AppModel {
	public  $name = 'Friend';
	public  $validate = array(
		'user_id' => array(
			'numeric' => array(
				'rule' => array('numeric'),
			),
		),
		'friendid' => array(
			'numeric' => array(
				'rule' => array('numeric'),
			),
		),
	);
	
	//The Associations below have been created with all possible keys, those that are not needed can be removed

	public  $belongsTo = array(
		'User' => array(
			'className' => 'User',
			'foreignKey' => 'user_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		)
	);

/**
 * Get following
 */
	public function getFollowing($user_id){
		$following_id = array(); 
		$following = $this->find('all', array(
				'recursive' => -1,
				'conditions' => array(
					'Friend.user_id' => $user_id,
					'Friend.status' => BAYON_STATUS_FRIEND_ACTIVE
				)
			)
		);
		foreach ($following as $f){
			$following_id[] = $f['Friend']['following'];
		}
		return $following_id;
	}

        public function getFriends($userId){
            $friends = $this->find('all', array(
				'recursive' => -1,
				'conditions' => array(
					'Friend.user_id' => $userId,
					'Friend.status' => BAYON_STATUS_FRIEND_ACTIVE
				)
			)
		);
            if($friends){
                return $friends;
            }
            return false;
        }
}
?>